package offer_2._66_constructArr;

public class constructArr {
    public int[] _constructArr(int[] a) {
        int n = a.length;
        if (n == 0)
            return new int[0];

        int[] A = new int[n];
        A[0] = 1;
        for (int i = 1; i < A.length; i++) {
            A[i] = A[i - 1] * a[i - 1];
        }

        int[] B = new int[n];
        B[n - 1] = 1;
        for (int i = n - 2; i >= 0; i--) {
            B[i] = B[i + 1] * a[i + 1];
        }

        int[] C = new int[n];
        for (int i = 0; i < C.length; i++) {
            C[i] = A[i] * B[i];
        }
        return C;
    }
}
